using System.ComponentModel.DataAnnotations;

namespace Lzfy_His_Service.Models
{
    /// <summary>
    /// 银行信息查询请求
    /// </summary>
    public class BankInfoQueryRequest
    {
        /// <summary>
        /// 搜索关键词
        /// </summary>
        public string? Keyword { get; set; }

        /// <summary>
        /// 是否只查询自定义银行
        /// </summary>
        public bool? IsCustomOnly { get; set; }

        /// <summary>
        /// 是否只查询启用的银行
        /// </summary>
        public bool? IsActiveOnly { get; set; } = true;

        /// <summary>
        /// 页码
        /// </summary>
        public int PageIndex { get; set; } = 1;

        /// <summary>
        /// 页大小
        /// </summary>
        public int PageSize { get; set; } = 20;
    }

    /// <summary>
    /// 银行信息创建请求
    /// </summary>
    public class BankInfoCreateRequest
    {
        /// <summary>
        /// 标准银行名称
        /// </summary>
        [Required(ErrorMessage = "银行名称不能为空")]
        [StringLength(100, ErrorMessage = "银行名称长度不能超过100个字符")]
        public string StandardName { get; set; } = string.Empty;

        /// <summary>
        /// 银行简称
        /// </summary>
        [StringLength(50, ErrorMessage = "银行简称长度不能超过50个字符")]
        public string? ShortName { get; set; }

        /// <summary>
        /// 英文名称
        /// </summary>
        [StringLength(100, ErrorMessage = "英文名称长度不能超过100个字符")]
        public string? EnglishName { get; set; }

        /// <summary>
        /// 银行代码
        /// </summary>
        [StringLength(20, ErrorMessage = "银行代码长度不能超过20个字符")]
        public string? BankCode { get; set; }

        /// <summary>
        /// 卡号长度规则
        /// </summary>
        [StringLength(50, ErrorMessage = "卡号长度规则不能超过50个字符")]
        public string? CardLengthRule { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsActive { get; set; } = true;

        /// <summary>
        /// 备注
        /// </summary>
        [StringLength(500, ErrorMessage = "备注长度不能超过500个字符")]
        public string? Remark { get; set; }

        /// <summary>
        /// 支持的卡类型
        /// </summary>
        [StringLength(100, ErrorMessage = "支持的卡类型长度不能超过100个字符")]
        public string? SupportedCardTypes { get; set; } = "debit,credit";

        /// <summary>
        /// 描述信息
        /// </summary>
        [StringLength(1000, ErrorMessage = "描述信息长度不能超过1000个字符")]
        public string? Description { get; set; }

        /// <summary>
        /// BIN码列表
        /// </summary>
        public List<string>? BinCodes { get; set; }

        /// <summary>
        /// 别名列表
        /// </summary>
        public List<BankAliasRequest>? Aliases { get; set; }
    }

    /// <summary>
    /// 银行信息更新请求
    /// </summary>
    public class BankInfoUpdateRequest
    {
        /// <summary>
        /// 银行ID
        /// </summary>
        [Required(ErrorMessage = "银行ID不能为空")]
        public int Id { get; set; }

        /// <summary>
        /// 标准银行名称
        /// </summary>
        [Required(ErrorMessage = "银行名称不能为空")]
        [StringLength(100, ErrorMessage = "银行名称长度不能超过100个字符")]
        public string StandardName { get; set; } = string.Empty;

        /// <summary>
        /// 银行简称
        /// </summary>
        [StringLength(50, ErrorMessage = "银行简称长度不能超过50个字符")]
        public string? ShortName { get; set; }

        /// <summary>
        /// 英文名称
        /// </summary>
        [StringLength(100, ErrorMessage = "英文名称长度不能超过100个字符")]
        public string? EnglishName { get; set; }

        /// <summary>
        /// 银行代码
        /// </summary>
        [StringLength(20, ErrorMessage = "银行代码长度不能超过20个字符")]
        public string? BankCode { get; set; }

        /// <summary>
        /// 卡号长度规则
        /// </summary>
        [StringLength(50, ErrorMessage = "卡号长度规则不能超过50个字符")]
        public string? CardLengthRule { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsActive { get; set; } = true;

        /// <summary>
        /// 备注
        /// </summary>
        [StringLength(500, ErrorMessage = "备注长度不能超过500个字符")]
        public string? Remark { get; set; }

        /// <summary>
        /// 支持的卡类型
        /// </summary>
        [StringLength(100, ErrorMessage = "支持的卡类型长度不能超过100个字符")]
        public string? SupportedCardTypes { get; set; } = "debit,credit";

        /// <summary>
        /// 描述信息
        /// </summary>
        [StringLength(1000, ErrorMessage = "描述信息长度不能超过1000个字符")]
        public string? Description { get; set; }

        /// <summary>
        /// BIN码列表
        /// </summary>
        public List<string>? BinCodes { get; set; }

        /// <summary>
        /// 别名列表
        /// </summary>
        public List<BankAliasRequest>? Aliases { get; set; }
    }

    /// <summary>
    /// 银行别名请求
    /// </summary>
    public class BankAliasRequest
    {
        /// <summary>
        /// 别名
        /// </summary>
        [Required(ErrorMessage = "别名不能为空")]
        [StringLength(100, ErrorMessage = "别名长度不能超过100个字符")]
        public string AliasName { get; set; } = string.Empty;

        /// <summary>
        /// 别名类型
        /// </summary>
        [StringLength(20, ErrorMessage = "别名类型长度不能超过20个字符")]
        public string AliasType { get; set; } = "COMMON";
    }

    /// <summary>
    /// 银行信息响应
    /// </summary>
    public class BankInfoResponse
    {
        /// <summary>
        /// 银行ID
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 标准银行名称
        /// </summary>
        public string StandardName { get; set; } = string.Empty;

        /// <summary>
        /// 显示名称（前端显示用）
        /// </summary>
        public string DisplayName => StandardName;

        /// <summary>
        /// 银行简称
        /// </summary>
        public string? ShortName { get; set; }

        /// <summary>
        /// 英文名称
        /// </summary>
        public string? EnglishName { get; set; }

        /// <summary>
        /// 银行代码
        /// </summary>
        public string? BankCode { get; set; }

        /// <summary>
        /// 卡号长度规则
        /// </summary>
        public string? CardLengthRule { get; set; }

        /// <summary>
        /// 最小卡号长度
        /// </summary>
        public int MinCardLength { get; set; } = 16;

        /// <summary>
        /// 最大卡号长度
        /// </summary>
        public int MaxCardLength { get; set; } = 19;

        /// <summary>
        /// 支持的卡类型
        /// </summary>
        public string? SupportedCardTypes { get; set; } = "debit,credit";

        /// <summary>
        /// 描述信息
        /// </summary>
        public string? Description { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsActive { get; set; }

        /// <summary>
        /// 是否为自定义银行
        /// </summary>
        public bool IsCustom { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdatedAt { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        public string? CreatedBy { get; set; }

        /// <summary>
        /// 更新人
        /// </summary>
        public string? UpdatedBy { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string? Remark { get; set; }

        /// <summary>
        /// BIN码列表
        /// </summary>
        public List<string> BinCodes { get; set; } = new List<string>();

        /// <summary>
        /// 别名列表
        /// </summary>
        public List<BankAliasResponse> Aliases { get; set; } = new List<BankAliasResponse>();
    }

    /// <summary>
    /// 银行别名响应
    /// </summary>
    public class BankAliasResponse
    {
        /// <summary>
        /// 别名ID
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 别名
        /// </summary>
        public string AliasName { get; set; } = string.Empty;

        /// <summary>
        /// 别名类型
        /// </summary>
        public string AliasType { get; set; } = string.Empty;

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsActive { get; set; }
    }

    /// <summary>
    /// 银行卡验证请求
    /// </summary>
    public class BankCardValidationRequest
    {
        /// <summary>
        /// 银行卡号
        /// </summary>
        [Required(ErrorMessage = "银行卡号不能为空")]
        public string CardNumber { get; set; } = string.Empty;

        /// <summary>
        /// 银行名称
        /// </summary>
        [Required(ErrorMessage = "银行名称不能为空")]
        public string BankName { get; set; } = string.Empty;
    }

    /// <summary>
    /// 银行卡验证响应
    /// </summary>
    public class BankCardValidationResponse
    {
        /// <summary>
        /// 验证是否通过
        /// </summary>
        public bool IsValid { get; set; }

        /// <summary>
        /// 卡号格式是否正确
        /// </summary>
        public bool CardNumberValid { get; set; }

        /// <summary>
        /// 银行名称是否有效
        /// </summary>
        public bool BankNameValid { get; set; }

        /// <summary>
        /// 银行是否匹配
        /// </summary>
        public bool BankMatch { get; set; }

        /// <summary>
        /// 检测到的银行
        /// </summary>
        public string? DetectedBank { get; set; }

        /// <summary>
        /// 标准化银行名称
        /// </summary>
        public string? StandardizedBankName { get; set; }

        /// <summary>
        /// 错误信息列表
        /// </summary>
        public List<string> Errors { get; set; } = new List<string>();

        /// <summary>
        /// 验证消息
        /// </summary>
        public string? Message { get; set; }
    }

    /// <summary>
    /// 银行搜索响应
    /// </summary>
    public class BankSearchResponse
    {
        /// <summary>
        /// 银行ID
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 银行名称
        /// </summary>
        public string Name { get; set; } = string.Empty;

        /// <summary>
        /// 银行简称
        /// </summary>
        public string? ShortName { get; set; }

        /// <summary>
        /// 英文名称
        /// </summary>
        public string? EnglishName { get; set; }

        /// <summary>
        /// 是否为自定义银行
        /// </summary>
        public bool IsCustom { get; set; }

        /// <summary>
        /// 匹配的别名
        /// </summary>
        public string? MatchedAlias { get; set; }
    }

    /// <summary>
    /// 分页响应基类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class PagedResponse<T>
    {
        /// <summary>
        /// 数据列表
        /// </summary>
        public List<T> Data { get; set; } = new List<T>();

        /// <summary>
        /// 总记录数
        /// </summary>
        public int TotalCount { get; set; }

        /// <summary>
        /// 当前页码
        /// </summary>
        public int PageIndex { get; set; }

        /// <summary>
        /// 页大小
        /// </summary>
        public int PageSize { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int TotalPages => (int)Math.Ceiling((double)TotalCount / PageSize);

        /// <summary>
        /// 是否有下一页
        /// </summary>
        public bool HasNextPage => PageIndex < TotalPages;

        /// <summary>
        /// 是否有上一页
        /// </summary>
        public bool HasPreviousPage => PageIndex > 1;
    }
}